<template>
  <div class="VonScrewTable">
    <div class="tableHeader">
      <ul>
        <li>螺丝号</li>
        <li>测试项</li>
        <li>下限</li>
        <li>上限</li>
        <li>单位</li>
        <li v-if="!isEdit">测试值</li>
        <li v-if="!isEdit">结果</li>
        <li v-if="isEdit" class="operator">操作</li>
      </ul>
    </div>
    <div class="tableBody">
      <div class="tableBodyItem" v-for="(item,index) in [...tableData]">
        <ul>
          <li v-if="item.length>0">
            <div class="testerLeft">{{'螺丝'+item[0].screwNo}}</div>
          </li>
          <li class="tester">
            <div class="testerRight">
              <span v-for="item1 in item" class="subTitle">{{item1.testName}}</span>
              <!-- <span class="subTitle">圈数</span> -->

            </div>
          </li>
          <li>
            <div v-for="item1 in item" class="testerItem">{{item1.lowerLimit}}</div>
          </li>
          <li>
            <div v-for="item1 in item" class="testerItem">{{item1.upperLimit}}</div>
          </li>
          <li>
            <div v-for="item1 in item" class="testerItem">{{item1.unit}}</div>
          </li>
          <li v-if="!isEdit">
            <div v-for="item1 in item" class="testerItem">{{item1.testData}}</div>
          </li>
          <li v-if="!isEdit">
            <div v-for="item1 in item" class="testerItem selected" :style="{color:item1.result == 'NG'?'red':'#0DFF1E'}">{{item1.result}}</div>
          </li>
          <li v-if="isEdit" class="operator">
            <el-button type="text" @click.stop="edit(item)">编辑</el-button>
            <el-button type="text" @click.stop="del(item)"> 删除</el-button>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "VonScrewTable",
  props: {
    isEdit: {
      type: Boolean,
      default: false
    },
    tableData: {
      type: Array,
      default() {
        return [
          {
            title: "螺丝22",
            testerItem: [
              {
                name: "扭矩",
                down: 2.34,
                up: 4.34,
                unit: "deg",
                test: "0.009",
                result: "pass"
              },
              {
                name: "圈数",
                down: 2.34,
                up: 4.34,
                unit: "deg",
                test: "0.009",
                result: "pass"
              },
              {
                name: "角度",
                down: 2.34,
                up: 4.34,
                unit: "deg",
                test: "0.009",
                result: "pass"
              }
            ]
          },
          {
            title: "螺丝23",
            testerItem: [
              {
                name: "扭矩",
                down: 2.34,
                up: 4.34,
                unit: "deg",
                test: "0.009",
                result: "pass"
              },
              {
                name: "圈数",
                down: 2.34,
                up: 4.34,
                unit: "deg",
                test: "0.009",
                result: "pass"
              },
              {
                name: "角度",
                down: 2.34,
                up: 4.34,
                unit: "deg",
                test: "0.009",
                result: "pass"
              }
            ]
          },
          {
            title: "螺丝24",
            testerItem: [
              {
                name: "扭矩",
                down: 2.34,
                up: 4.34,
                unit: "deg",
                test: "0.009",
                result: "pass"
              },
              {
                name: "圈数",
                down: 2.34,
                up: 4.34,
                unit: "deg",
                test: "0.009",
                result: "pass"
              },
              {
                name: "角度",
                down: 2.34,
                up: 4.34,
                unit: "deg",
                test: "0.009",
                result: "pass"
              }
            ]
          }
        ];
      }
    }
  },
  methods: {
    edit(row) {
      this.$emit("edit", row);
    },
    del(row) {
      this.$emit("del", row);
    }
  }
};
</script>

<style scoped lang="scss">
.VonScrewTable {
  width: 100%;
  height: 100%;
  .tableHeader {
    width: 100%;
    height: 30px;
    background: rgba(143, 163, 204, 0.2);
    color: white;
    ul {
      height: 30px;
      display: flex;
      line-height: 30px;
      font-size: 16px;
      li {
        text-align: center;
        width: 15%;
        list-style: none;
        font-weight: bold;
      }
      .operator {
        width: 25%;
      }
    }
  }
  .tableBody {
    color: white;
    ul {
      height: 28px;
      display: flex;
      line-height: 28px;
      font-size: 18px;
      li {
        text-align: center;
        width: 15%;
        list-style: none;
      }
    }
    .tableBodyItem {
      width: 100%;
      height: 60px;
      border-bottom: 1px solid #cbf1ff;
      ul {
        height: 30px;
        display: flex;
        line-height: 60px;
        font-size: 16px;
        li {
          text-align: center;
          width: 15%;
          list-style: none;
          .testerItem {
            height: 28px;
            text-align: center;
            line-height: 28px;
            width: 100%;
          }
          .selected {
            color: #2adc8b;
          }
        }
        .operator {
          width: 25%;
        }
        .tester {
          display: flex;
          .testerLeft {
            width: 40%;
          }
          .testerRight {
            display: flex;
            flex-direction: column;
            color: white;
            flex: 1;
            height: 100px;
            .subTitle {
              display: inline-block;
              width: 100px;
              height: 28px;
              text-align: center;
              line-height: 28px;
            }
          }
        }
      }
    }
  }
}
</style>
